<?php

class CBusiness extends Zend_Db_Table{
	
	protected $_name;
	
	protected $_primary;

	public function __construct(){
		
		$this->_name=R_PRE."businesses";
		
		$this->_primary="businessid";
		
		parent::__construct();
		
	}

	public function createBusiness($data){
		
		$businessid=$this->insert($data);
		
		return $businessid;
		
	}
	
	public function getBusinessCounts(){
		
		$db=$this->getAdapter();
		
		$select = $db->select();
		
		$select->from($this->_name,'COUNT(*)');
		
		return $db->fetchOne($select);
		
	}
	
	public function getBusinesses(){
		
		$db=$this->getAdapter();
		
		$select = $db->select();
		
		$select->from($this->_name,'*');
		
		$select->order("businessid ASC");
		
		return $db->fetchAll($select);
		
	}

	public function delBusinesses($businessidArray){
		
		$db=$this->getAdapter();
		
		$businessidString=join(',',$businessidArray);
		
		$result=$db->query("DELETE FROM $this->_name WHERE businessid IN ($businessidString)");
		
		return $result;
		
	}
	
	public function editBusiness($businessid,$data){
		
		$db=$this->getAdapter();
		
		$where = $db->quoteInto('businessid = ?', $businessid);
		
		$rows_affected=$db->update($this->_name,$data,$where);
		
		if($rows_affected!=1){
			
			return false;
			
		}else{
			
			return true;
			
		}
		
		
	}
	

	
}